import 'package:baixing/provide/child_category.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:provide/provide.dart';

import './pages/index_page.dart';
import './routers/routes.dart';
import 'provide/cart.dart';
import 'provide/category_goods_provide.dart';
import 'provide/counter.dart';
import 'provide/currentIndex.dart';
import 'provide/details_info.dart';
import 'routers/application.dart';

//json.decode(cartString.toString())  转成Json格式
//json.encode(tempList).toString()    转成String格式
void main() {
  var counter = Counter();
  var childCategory = ChildCategory();
  var categoryGoodsProvide = CategoryGoodsProvide();
  var detailInfoProvide = DetailInfoProvide();
  var cartProvide = CartProvide();
  var providers = Providers();
  var currentIndex = CurrentIndexProvide();

  providers..provide(Provider.function((context) => counter))..provide(
      Provider<ChildCategory>.value(childCategory))..provide(
      Provider<CategoryGoodsProvide>.value(categoryGoodsProvide))..provide(
      Provider<DetailInfoProvide>.value(detailInfoProvide))..provide(
      Provider<CartProvide>.value(cartProvide))..provide(
      Provider<CurrentIndexProvide>.value(currentIndex));
  runApp(ProviderNode(child: MyApp(), providers: providers));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final router = Router();
    Routes.configureRoutes(router);
    Application.router = router;

    return Container(
        child: MaterialApp(
          title: "百姓生活+",
          onGenerateRoute: Application.router.generator,
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            primarySwatch: Colors.pink,
          ),
          home: IndexPage(),
        ));
  }
}
